#!/bin/bash
log_home=/opt/module/gmall0922
app_name=gmall-logger-0.0.1-SNAPSHOT.jar
# 日志采集脚本
# 1. 启动nginx
# 2. 每台设备启动日志服务器
case $1 in
"start")
    if [[ -z "`ps -ef | awk '/nginx/ && !/awk/ {print $n}'`" ]]; then
        echo "在 hadoop162 启动 nginx"
        /opt/module/nginx/sbin/nginx
    else
        echo "nginx 已经启动, 无需重复启动"
    fi
    for host in hadoop162 hadoop163 hadoop164 ; do
        echo "在 $host 启动日志服务器"
        ssh ${host} "nohup java -jar -Xms32m -Xmx64m $log_home/$app_name > /dev/null 2>&1 &"
    done


;;
"stop")
    for host in hadoop162 hadoop163 hadoop164 ; do
        echo "在 $host 停止日志服务器"
        ssh $host "jps -l | awk '/gmall-logger-0.0.1-SNAPSHOT/ {print \$1}' | xargs kill -9"
    done
    echo "在 hadoop162 停止 nginx"
    /opt/module/nginx/sbin/nginx -s stop
;;
*)
    echo "你启动的姿势不对"
    echo "  log.sh start 启动日志采集"
    echo "  log.sh stop  停止日志采集"
;;
esac
